package com.eascs.p2p.admin.service.impl;


import java.util.List;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.p2p.admin.manager.IFileManager;
import com.eascs.p2p.common.entity.FileEntity;
import com.eascs.p2p.common.service.IFileService;
import com.eascs.p2p.common.vo.ModelResult;

@Service
public class FileServiceImpl implements IFileService{
	
	@Inject
	IFileManager iFileManager;
	
	
	@Override
	public ModelResult<List<FileEntity>> findFileByKeyCode(String[] type, String id) {
		ModelResult<List<FileEntity>> model=new ModelResult<List<FileEntity>>();
		try {
			model.setModel(iFileManager.findFileByKeyCode(type, id));
		} catch (Exception e) {
			e.printStackTrace();
			model.withError("按业务code查询附件报错", e.getMessage());
		}
		return model;
	}



	@Override
	public ModelResult<FileEntity> findFileById(String id) {
		ModelResult<FileEntity> model=new ModelResult<FileEntity>();
		try {
			model.setModel(iFileManager.findFileById(id));
		} catch (Exception e) {
			e.printStackTrace();
			model.withError("按主键查询附件报错", e.getMessage());
		}
		return model;
	}



	@Override
	public ModelResult<String> fileUpload(FileEntity fileEntity) {
		ModelResult<String> model=new ModelResult<String>();
		try {
			boolean flag = iFileManager.save(fileEntity);
			if(flag==true){
				model.setModel(fileEntity.getFileId());
			}
		} catch (Exception e) {
			e.printStackTrace();
			model.withError("附件信息保存失败", e.getMessage());
		}
		return model;
	}
	
	
	@Override
	public ModelResult<Boolean> delFile(String fileId) {
		ModelResult<Boolean> model=new ModelResult<Boolean>();
		try {
			model.setModel(iFileManager.delFile(fileId));
		} catch (Exception e) {
			e.printStackTrace();
			model.withError("附件信息删除失败", e.getMessage());
		}
		return model;
	}



	@Override
	public ModelResult<Boolean> updateFile(String[] fileId, String keyCode) {
		ModelResult<Boolean> model=new ModelResult<Boolean>();
		try {
			iFileManager.updateFile(fileId,keyCode);
		} catch (Exception e) {
			e.printStackTrace();
			model.withError("附件信息删除失败", e.getMessage());
		}
		return model;
	}

}
